package com.ibiaoke.system.service;

import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.consts.CommonConsts;
import com.ibiaoke.common.utils.AssertUtils;
import com.ibiaoke.system.dao.XcxTopicPageDao;
import com.ibiaoke.system.entity.XcxTopicPage;
import com.ibiaoke.system.entity.vo.XcxTopicPageVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author Dragon
 * @date 2018/4/9/9:20;
 */
@Service
public class XcxTopicPageServiceImpl implements XcxTopicPageService{
    @Autowired
    private XcxTopicPageDao topicPageDao;

    /**
     * 保存专题活动页
     * @param xcxTopicPageVO
     * @return
     */
    @Override
    public int saveXcxTopicPage(XcxTopicPageVO xcxTopicPageVO) {
        XcxTopicPage topicPage = new XcxTopicPage();
        BeanUtils.copyProperties(xcxTopicPageVO, topicPage);
        topicPage.setCreateTime(new Date());
        topicPage.setUpdateTime(new Date());
        topicPage.setDelStatus(CommonConsts.NO);
        return topicPageDao.insertSelective(topicPage);
    }

    /**
     * 修改专题活动页
     * @param xcxTopicPageVO
     * @return
     */
    @Override
    public int updateXcxTopicPage(XcxTopicPageVO xcxTopicPageVO) {
        AssertUtils.notNull(xcxTopicPageVO.getXcxTopicPageId(), "专题id不能为空");
        XcxTopicPage topicPage = new XcxTopicPage();
        BeanUtils.copyProperties(xcxTopicPageVO, topicPage);
        topicPage.setUpdateTime(new Date());
        return topicPageDao.updateByPrimaryKeySelective(topicPage);
    }

    /**
     * 查询正常的专题活动页
     * @param page
     * @return
     */
    @Override
    public List<XcxTopicPage> listXcxTopicPage(Integer position,Integer showStatus,Page page) {
        return topicPageDao.listTopicPage(position,showStatus,page);
    }

    /**
     * 获取专题活动页详情
     * @param topicPageId
     * @return
     */
    @Override
    public XcxTopicPage getXcxTopicPage(Integer topicPageId) {
        AssertUtils.notNull(topicPageId, "专题活动页Id不能为空");
        return topicPageDao.selectByPrimaryKey(topicPageId);
    }

    /**
     * 删除专题活动页
     * @param xcxTopicPageId
     * @return
     */
    @Override
    public int deleteXcxTopicPage(Integer xcxTopicPageId) {
        AssertUtils.notNull(xcxTopicPageId, "专题活动页Id不能为空");
        XcxTopicPage topicPage = new XcxTopicPage();
        topicPage.setUpdateTime(new Date());
        topicPage.setTopicPageId(xcxTopicPageId);
        topicPage.setDelStatus(CommonConsts.YES);
        return topicPageDao.updateByPrimaryKeySelective(topicPage);
    }

    @Override
    public List<XcxTopicPage> listTopicPage(Integer position, Integer shopId, Integer showStatus, Page page) {
        return topicPageDao.listTopicPageByShopId(position,shopId,showStatus,page);
    }

    @Override
    public XcxTopicPage getTopicPage(Integer topicPageId) {
        AssertUtils.notNull(topicPageId, "专题活动页Id不能为空");
        return topicPageDao.selectByPrimaryKey(topicPageId);
    }
}
